﻿using System.IO;
using Microsoft.Extensions.Configuration;

namespace DBEntitie
{
   public sealed class ConfigurationManager
   {
        private static ConfigurationManager _instance;
        private static readonly object Lockobj = new object();
        private readonly IConfigurationRoot _config;
        private ConfigurationManager()
        {
            _config = new ConfigurationBuilder()
            .AddInMemoryCollection()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json", true, true)
            .Build();
        }

        private static ConfigurationManager Instance
        {
            get
            {
                if (_instance != null) return _instance;

                lock (Lockobj)
                {
                    _instance = new ConfigurationManager();
                }

                return _instance;
            }
        }

       public static string ConnectionStrings(string connectionName)
       {
            return Instance._config["ConnectionStrings:" + connectionName];
        }

       public static string AppSettings(string key)
       {
            return Instance._config["AppSettings:" + key];
        }
    }
}
